package com.tal.pad.javabase.arithtest;

public class NodeTest {


    static class  Node{

      public  int value;
      public  Node next;
    }

    public static Node buildNode(int [] arrs){
        if(arrs ==null || arrs.length<1){
            return null;
        }
        Node listHead = new Node();
        listHead.value = arrs[0];
        Node temp = listHead;
        for(int i =1; i<arrs.length; i++){
            Node node = new Node();
            node.value = arrs[i];
            temp.next = node;
            temp = node;
        }
        return listHead;
    }

    public static Node reverseNodeList(Node node){
        if(node ==null || node.next ==null){
            return node;
        }
        Node pre = null;
        Node current = node;
        while(current!=null){
            Node temp = current.next;
            current.next = pre;
            pre = current;
            current  = temp;
        }
        return pre;
    }

    public static void printNode(Node node){
        while(node!=null){
            System.out.print(node.value + " ");
            node = node.next;
        }
    }


    public static void main(String[] args) {
//        int[] ints = SortTest.genRandArr(10, 10);
//        SortTest.printArr(ints);
//        Node node = buildNode(ints);
//        printNode(node);
//        reverseNodeList(node);
//        printNode(node);
    }

}
